﻿using System.Management.Automation;
using System;
using System.Collections.Generic;
using System.Text;

//==============================================================================================================================================//

namespace VDICmdlets
{
    public class Fxns
    {
        public Fxns()
        { }

        public void login(string address,string uname,string passwd)
        {
            var LogResponse = new webproxy.LoginResponse();
            var webserv1 = new webproxy.ConnectionBrokerService();
            LogResponse = webserv1.AdminLogin(address, uname, passwd);
            try
            {
                if (LogResponse.StatusCode != 1)
                    throw new UnauthorizedAccessException();
                else
                {
                    System.Environment.SetEnvironmentVariable("sessionkey", LogResponse.sessionKey);
                    System.Environment.SetEnvironmentVariable("adminname", uname);
                    System.Environment.SetEnvironmentVariable("passwd", passwd);
                    Console.WriteLine("\nLogged in successfully........\n");
                }
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
        }

        public void logout(string sessionkey)
        {
            var webserv1 = new webproxy.ConnectionBrokerService();
            webserv1.AdminLogout(sessionkey);
        }

        public webproxy.AdminUserResponse addusers(string dname,string uname,string domname,webproxy.ClientType utype)
        {
            //Code to add adminuser to the VDI console................................
            var webserv1 = new webproxy.ConnectionBrokerService();
            string sessionkey;

            sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
            webproxy.AdminUser[] admuser = new webproxy.AdminUser[1];
            admuser[0] = new webproxy.AdminUser();
            admuser[0].ClientDisplayName = dname;
            admuser[0].ClientName = uname;
            admuser[0].ClientType = utype;
            admuser[0].ClientTypeSpecified = true;
            admuser[0].DomainName = domname;

            var admuserresponse = new webproxy.AdminUserResponse();
            admuserresponse = webserv1.AddAdminUsers(admuser,sessionkey);
            return admuserresponse;
        }

        public webproxy.AdminUserResponse getadmusers(string sessionkey,webproxy.ClientType utype,string domname)
        {
            var admuserfilter = new webproxy.AdminUserFilter();
            var admuserresponse = new webproxy.AdminUserResponse();
            var webserv1 = new webproxy.ConnectionBrokerService();
                admuserfilter.ClientType = utype;
                admuserfilter.SelectFlag = webproxy.SelectFlag.UseFilter;
                admuserfilter.DimainName = domname;
                admuserfilter.ClientTypeSpecified = true;
                admuserfilter.SelectFlagSpecified = true;
                admuserresponse = webserv1.GetAdminUsers(admuserfilter, sessionkey);
            return admuserresponse;
        }

        public webproxy.VHostResponse getVHosts(string sessionkey,webproxy.VitualPlatforms vplatform, webproxy.VirtualizationProductType vptype)
        {
            var vhResponse = new webproxy.VHostResponse();
            var VHFilter = new webproxy.VHostFilter();
            var VHAttributeSelectFlag = new webproxy.VHAttributeSelectFlag();
            var webserv1 = new webproxy.ConnectionBrokerService();
            VHFilter.VirtualizationProductType = vptype;  //specified the type of Virtualization Host......
            VHFilter.VirtualHostType = vplatform;
            VHFilter.SelectFlag = webproxy.SelectFlag.UseFilter;
            VHFilter.SelectFlagSpecified = true;
            VHAttributeSelectFlag.IsAssignedRequired = false;      // Are these required??
            VHAttributeSelectFlag.ReturnAllFlag = true;            // Are these required??
            VHAttributeSelectFlag.IsEnabledRequired = true;        // Are these required??
            VHFilter.VirtualizationProductTypeSpecified = true;
            VHFilter.VirtualHostTypeSpecified = true;
            VHAttributeSelectFlag.IsAssignedRequiredSpecified = true;
            VHAttributeSelectFlag.ReturnAllFlagSpecified = true;
            VHAttributeSelectFlag.IsEnabledRequiredSpecified = true;
            vhResponse = webserv1.GetVHost(VHFilter, VHAttributeSelectFlag, sessionkey);
            return vhResponse;
        }

        public webproxy.DataCenterResponse getdatacenters(string sessionkey,webproxy.VirtualizationType vtype,webproxy.VirtualizationProductType vprodtype)
        {
            var dcResponse = new webproxy.DataCenterResponse();
            var dcFilter = new webproxy.DataCenterFilter();
            var dcAttrSelectFlag = new webproxy.DCAttributesSelectFlag();
            var webserv1 = new webproxy.ConnectionBrokerService();
            dcFilter.DataCenterType = vtype;
            dcFilter.VirtualizationProductType = vprodtype;
            dcFilter.SelectFlag = webproxy.SelectFlag.UseFilter;
            dcFilter.SelectFlagSpecified = true;
            dcAttrSelectFlag.IsDatacenterTypeRequired = 1;
            dcAttrSelectFlag.IsVirtualizationTypeRequired = 1;
            dcAttrSelectFlag.ReturnAllFlag = 1;
            dcFilter.DataCenterTypeSpecified = true;
            dcFilter.VirtualizationProductTypeSpecified = true;
            dcAttrSelectFlag.IsDatacenterTypeRequiredSpecified = true;
            dcAttrSelectFlag.IsVirtualizationTypeRequiredSpecified = true;
            dcAttrSelectFlag.ReturnAllFlagSpecified = true;
            dcResponse = webserv1.GetDataCenter(dcFilter, dcAttrSelectFlag, sessionkey);
            return dcResponse;
        }

        public webproxy.ClientResponse getClients(string sessionkey,webproxy.ClientType ctype,string domname)
        {
            var ClientResponse = new webproxy.ClientResponse();
            var clientFilter = new webproxy.ClientFilter();
            var clientAttributeSelectFlag = new webproxy.ClientAttributeSelectFlag();
            var webserv1 = new webproxy.ConnectionBrokerService();
            clientAttributeSelectFlag.UpdateIsEnabled = true;
            clientFilter.ClientType = ctype;
            clientFilter.DomainName = domname;
            ClientResponse = webserv1.GetClients(clientFilter, clientAttributeSelectFlag, sessionkey);
            return ClientResponse;
        }

        public webproxy.ManagedDesktopResponse getmanageddesktop(string sessionkey)
        {
            var webserv1 = new webproxy.ConnectionBrokerService();
            var MDResponse = new webproxy.ManagedDesktopResponse();
            var MDFilter = new webproxy.ManagedDesktopFilter();
            var MDAttributeSelectFlag = new webproxy.MDAttributeSelectFlag();
            /**/
            MDFilter.ReturnAll = true;
            MDFilter.SelectFlag = webproxy.SelectFlag.All;
            MDFilter.SelectFlagSpecified = true;
            MDFilter.ReturnAllSpecified = true;

            /*
            MDFilter.DataCenterName = "ss";
            MDFilter.GetMDByVH = true;
            MDFilter.GetMDByVHSpecified = true;
            MDFilter.ReturnAll = true;
            MDFilter.SelectFlag = webproxy.SelectFlag.UseFilter;
            MDFilter.VirtualHostName = "s1";
            MDFilter.VirtualHostType = webproxy.VitualPlatforms.ParallelsVirtuozzo;
            MDFilter.VirtualHostTypeSpecified = true;
            MDFilter.CommandTypeFlag = webproxy.CommandType.Insert;
            MDFilter.SelectFlagSpecified = true;
            MDFilter.ReturnAllSpecified = true;
            MDFilter.MDSIDOnVHost = "s1";
            MDFilter.AdminUserName = "administrator";
            MDFilter.AdminPassword = "sharma";

             */
            MDAttributeSelectFlag.ReturnAllFlag = true;
            MDAttributeSelectFlag.ReturnAllFlagSpecified = true;
            

            MDResponse = webserv1.GetManagedDesktop(MDFilter, MDAttributeSelectFlag, sessionkey);
            return MDResponse;
        }

        public webproxy.ClientType getfilter(string utype)
        {
            var filter = new webproxy.ClientType();
                if (utype.ToUpper() == "USER")
                    filter = webproxy.ClientType.User;
                else if (utype.ToUpper() == "GROUP")
                    filter = webproxy.ClientType.Group;
                else if (utype.ToUpper() == "IPV4ADDRESS")
                    filter = webproxy.ClientType.IPv4Address;
                else if (utype.ToUpper() == "IPV4ADDRESSRANGE")
                    filter = webproxy.ClientType.IPv4AddressRange;
                else if (utype.ToUpper() == "IPV4NETID")
                    filter = webproxy.ClientType.IPv4NetID;
                else if (utype.ToUpper() == "ORGANIZATIONALUNIT")
                    filter = webproxy.ClientType.OrganizationalUnit;
                else
                    filter = webproxy.ClientType.None;
            return filter;
        }

        public webproxy.VitualPlatforms getplatform(string vpname)
        {
            var platform = new webproxy.VitualPlatforms();
            if (vpname.ToUpper() == "OTHERSPHYSICAL")
                platform = webproxy.VitualPlatforms.OthersPhysical;
            else if (vpname.ToUpper() == "PARALLELSVIRTUOZZO")
                platform = webproxy.VitualPlatforms.ParallelsVirtuozzo;
            else if (vpname.ToUpper() == "PARALLELSVIRTUOZZOSOAP")
                platform = webproxy.VitualPlatforms.ParallelsVirtuozzoSOAP;
            else if (vpname.ToUpper() == "VMWARE")
                platform = webproxy.VitualPlatforms.VMWare;
            else
                platform = webproxy.VitualPlatforms.None;
            return platform;
        }

        public webproxy.VirtualizationProductType getproducttype(string vptype)
        {
            var producttype = new webproxy.VirtualizationProductType();
            if (vptype.ToUpper() == "PARALLELSCONTAINER")
                producttype = webproxy.VirtualizationProductType.parallelsContainer;
            else if (vptype.ToUpper() == "PARALLELSSERVER")
                producttype = webproxy.VirtualizationProductType.parallelsContainer;
            else if (vptype.ToUpper() == "VMWAREESX")
                producttype = webproxy.VirtualizationProductType.parallelsContainer;
            else if (vptype.ToUpper() == "VMWARESERVER")
                producttype = webproxy.VirtualizationProductType.parallelsContainer;
            else if (vptype.ToUpper() == "VMWAREWORKSTATION")
                producttype = webproxy.VirtualizationProductType.parallelsContainer;
            else
                producttype = webproxy.VirtualizationProductType.none;
            return producttype;
        }

        public webproxy.VirtualizationType getvirtualizationtype(string vtype)
        {
            var virtype = new webproxy.VirtualizationType();
            if (vtype.ToUpper() == "OTHERSPHYSICAL")
                virtype = webproxy.VirtualizationType.OthersPhysical;
            else if (vtype.ToUpper() == "PARALLELS")
                virtype = webproxy.VirtualizationType.parallels;
            else if (vtype.ToUpper() == "VMWARE")
                virtype = webproxy.VirtualizationType.vmware;
            else
                virtype = webproxy.VirtualizationType.none;
            return virtype;
        }
    }

//===============================================================================================================================================
    [Cmdlet(VerbsCommon.Get, "AdminLogin", SupportsShouldProcess = true)]   //get-AdminLogin -IPAddress -UserName -Password
    public class admlogin : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the IP Adress of ConnectionBroker machine...")]
        [ValidateNotNullOrEmpty]

        public string IPAdress
        {
            set { ip = value; }
        }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Username...")]
        //[Alias("UserName")]
        [ValidateNotNullOrEmpty]

        public string UserName
        {
            set { uname = value; }
        }

        [Parameter(Position = 2,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the password...")]
        //[Alias("Password")]
        [ValidateNotNullOrEmpty]

        public string Password
        {
            set { passwd = value; }
        }

        #endregion

        private string ip;
        private string uname;
        private string passwd;

        protected override void ProcessRecord()
        {
            Fxns f1 = new Fxns();
            f1.login(ip, uname, passwd);
        }
    }

//===============================================================================================================================================

    [Cmdlet(VerbsCommon.Get, "AdminUsers", SupportsShouldProcess = true)]  //Get-AdminUsers [-UserType -DomainName]
    public class getusers : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Usertype to be fetched from database...")]
        [ValidateNotNullOrEmpty]

        public string UserType
        {
            set { utype = value; }
        }

        [Parameter(Position = 1,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the DomainName to be fetched from database...")]
        [ValidateNotNullOrEmpty]

        public string DomainName
        {
            set { domname = value; }
        }
        #endregion

        private string utype = "User";
        private string domname = "localhost";
        protected override void ProcessRecord()
        {
                    string sessionkey;
                    var clienttype = new webproxy.ClientType();
                    var admuserresponse = new webproxy.AdminUserResponse();
                    try
                    {
                        Fxns f1 = new Fxns();
                        sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                        if (utype.ToUpper() == "USER")
                            clienttype = webproxy.ClientType.User;
                        else if (utype.ToUpper() == "GROUP")
                            clienttype = webproxy.ClientType.Group;
                        else
                            throw new ArgumentException();
                        admuserresponse = f1.getadmusers(sessionkey, clienttype,domname);
                        if (admuserresponse.StatusCode != 1)
                            throw new FieldAccessException();
                        else
                        {
                            base.WriteObject(admuserresponse);
                        }
                    }
                    catch (FieldAccessException)
                    {
                        Console.WriteLine("\n\tError generated!!! \n\t" + admuserresponse.StatusCodeMessage + "\n");
                    }
                    catch (ArgumentException)
                    {
                        Console.WriteLine("\n\tWrong Clienttype Specified!!!!\n\t Check it and try again!!! \n");
                    }
          }
    }

//===============================================================================================================================================

    [Cmdlet(VerbsCommon.Remove, "AdminUser", SupportsShouldProcess = true)] //Remove-AdminUser -Name [-UserType -DomainName]
    public class removeuser : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the name of user to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string Name
        {
            set { uname = value; }
        }

        [Parameter(Position = 1,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Usertype of User to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string UserType
        {
            set { utype = value; }
        }

        [Parameter(Position = 2,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the DomainName of User to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string DomainName
        {
            set { domname = value; }
        }
        #endregion

        private string uname;
        private string utype = "User";
        private string domname="localhost";

        protected override void ProcessRecord()
        {
            #region vars
            var webserv1=new webproxy.ConnectionBrokerService();
            var admuserfilter = new webproxy.AdminUserFilter();
            var admuserresponse = new webproxy.AdminUserResponse();
            var LogResponse = new webproxy.LoginResponse();
            var Response = new webproxy.Response();
            webproxy.AdminUser[] deladmuser = new webproxy.AdminUser[1];
            var clienttype = new webproxy.ClientType();
            string sessionkey;
            int flag = 0,i=0;
            #endregion

            try
            {
                Fxns f1 = new Fxns();
                if (utype.ToUpper() == "NONE")
                    clienttype = webproxy.ClientType.None;
                else
                {
                    clienttype = f1.getfilter(utype);
                    if (clienttype == webproxy.ClientType.None)
                        throw new ArgumentException();
                }

                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                admuserresponse = f1.getadmusers(sessionkey, clienttype, domname);
                if (admuserresponse.StatusCode != 1)
                    throw new UnauthorizedAccessException();
                else
                {
                    for (i = 0; i < admuserresponse.ListOfAdminUsers.Length; i++)
                    {
                        if (uname.ToUpper() == admuserresponse.ListOfAdminUsers[i].ClientName.ToUpper())
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 0)
                        Console.WriteLine("User not found!!!!!");
                    else
                    {
                        Console.WriteLine("User Found.... Deleting User.....");
                        deladmuser[0] = new webproxy.AdminUser();
                        deladmuser[0] = admuserresponse.ListOfAdminUsers[i];
                        Response = webserv1.DeleteAdminUsers(deladmuser, sessionkey);
                        if (Response.StatusCode == 1)
                            Console.WriteLine("\nUser Deleted Successfully..........\n");
                        else
                            Console.WriteLine("\nError in deleting!!!\nMessage ::" + Response.StatusCodeMessage);
                    }
                }
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nWrong ClientType specified!!! \nPlease check and try again!!!\n");
            }
        }
    }

//===============================================================================================================================================

    [Cmdlet(VerbsCommon.Add, "AdminUser", SupportsShouldProcess = true)]    //Add-AdminUser -DisplayName -UserName -DomainName [-UserType]
    public class adduser : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Client Display Name...")]
        [ValidateNotNullOrEmpty]

        public string DisplayName
        {
            set { dname = value; }
        }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Client Name...")]
        [ValidateNotNullOrEmpty]

        public string UserName
        {
            set { uname = value; }
        }

        [Parameter(Position = 2,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Domain Name...")]
        [ValidateNotNullOrEmpty]

        public string DomainName
        {
            set { domname = value; }
        }

        [Parameter(Position = 3,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the User Type.......")]
        [ValidateNotNullOrEmpty]

        public string UserType
        {
            set { utype = value; }
        }
        #endregion

        private string dname;
        private string uname;
        private string domname;
        private string utype="User";

        protected override void ProcessRecord()
        {
            #region vars
            string adminname, passwd,sessionkey;
            var admuserresponse = new webproxy.AdminUserResponse();
            var filter = new webproxy.ClientType();
            var webserv1 = new webproxy.ConnectionBrokerService();
            int flag = 0,i=0;
            #endregion
            
            try
            {
                if (utype.ToUpper() == "USER")
                    filter = webproxy.ClientType.User;
                else if (utype.ToUpper() == "GROUP")
                    filter = webproxy.ClientType.Group;
                else
                    throw new ArgumentException();

                adminname = System.Environment.GetEnvironmentVariable("adminname");
                passwd = System.Environment.GetEnvironmentVariable("passwd");
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                webproxy.ADObject[] x = webserv1.GetDomainClients(domname, uname, passwd, filter, true, sessionkey);
                if (x.Length == 0)
                    Console.WriteLine("\nError retrieving names from SAM database.... Zero users retrieved......\n");
                else
                {
                    Fxns f1 = new Fxns();
                    for (i = 0; i < x.Length; i++)
                    {
                        if (x[i].ObjectName.ToUpper() == uname.ToUpper())
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 0)
                        Console.WriteLine("\nUser not present in SAM database...... Can't add the user to Management Console.....\n");
                    else
                    {
                        admuserresponse = f1.addusers(x[i].ObjectName, x[i].ObjectInternalName, domname.ToLower(), filter);
                        if (admuserresponse.StatusCode != 1)
                            Console.WriteLine("Error:: " + admuserresponse.StatusCodeMessage);
                        else
                            base.WriteObject(admuserresponse);
                    }
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nUserType specified is wrong!!! \nCheck it and try again!!!\n");
            }
            
            /*
            Fxns f1 = new Fxns();
            filter = webproxy.ClientType.User;
                    admuserresponse = f1.addusers(dname,uname,domname,filter);
                    if (admuserresponse.StatusCode != 1)
                        Console.WriteLine("Error:: " + admuserresponse.StatusCodeMessage);
                    else
                        Console.WriteLine("User added successfully. Message:: " + admuserresponse.StatusCodeMessage);
            */ 
        }
    }

//==============================================================================================================================================//
    
    [Cmdlet(VerbsCommon.Get, "Clients", SupportsShouldProcess = true)]     //Get-Clients [-ClientType -DomainName]
    public class getclients : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the ClientType to be fetched from database...")]
        [ValidateNotNullOrEmpty]

        public string ClientType
        {
            set { ctype = value; }
        }

        [Parameter(Position = 1,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the DomainName to be fetched from database...")]
        [ValidateNotNullOrEmpty]

        public string DomainName
        {
            set { domname = value; }
        }
        #endregion

        private string ctype = "User";
        private string domname = "localhost";
        protected override void ProcessRecord()
        {
            #region vars
            string sessionkey;
            var filter = new webproxy.ClientType();
            var ClientResponse = new webproxy.ClientResponse();
            #endregion

            try
            {
                Fxns f1 = new Fxns();
                if (ctype.ToUpper() == "NONE")
                    filter = webproxy.ClientType.None;
                else
                {
                    filter = f1.getfilter(ctype);
                    if (filter == webproxy.ClientType.None)
                        throw new ArgumentException();
                }
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");

                ClientResponse = f1.getClients(sessionkey,filter,domname);
                if (ClientResponse.StatusCode != 1)
                    Console.WriteLine("Error:: " + ClientResponse.StatusCodeMessage);
                else
                {
                    base.WriteObject(ClientResponse);
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nWrong ClientType specified!!! \nPlease check and try again!!!\n");
            }
          }
    }

//==============================================================================================================================================//
    [Cmdlet(VerbsCommon.Get, "DomainClients", SupportsShouldProcess = true)] //Get-DomainClients [-ClientType -DomainName]
    public class getdomainclients : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the ClientType.....")]
        [ValidateNotNullOrEmpty]

        public string ClientType
        {
            set { ctype = value; }
        }
        
        [Parameter(Position = 1,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Client's Domain Name...")]
        [ValidateNotNullOrEmpty]

        public string DomainName
        {
            set { dname = value; }
        }
        #endregion

        private string dname = "localhost";
        private string ctype = "user";

        protected override void ProcessRecord()
        {
            #region vars
            string uname,passwd;
            string sessionkey;
            var filter = new webproxy.ClientType();
            var webserv1 = new webproxy.ConnectionBrokerService();
            #endregion
            
            Fxns f1 = new Fxns();

            try
            {
                if (ctype.ToUpper() == "NONE")
                    filter = webproxy.ClientType.None;
                    /*Whenever an object of clienttype is created,it is by default specified to None. So when the user enters a wrong clienttype and 
                     it is not found in the getfilter(string x) function, then it returns filter as None. So if user has entered clienttype as None, 
                     it is checked first and if it is not, then if None comes back from the getfilter function, then its sure it is a wrong type specified.
                     Thats why we have checked the condition for None earlier so that there is no conflict......*/
                else
                {
                    filter=f1.getfilter(ctype);
                    if(filter==webproxy.ClientType.None)
                    {
                        Console.WriteLine("\nSpecify the correct ClientType..........");
                        throw new ArgumentException();
                    }
                }
                
                uname = System.Environment.GetEnvironmentVariable("adminname");
                passwd = System.Environment.GetEnvironmentVariable("passwd");
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                webproxy.ADObject[] x = webserv1.GetDomainClients(dname, uname, passwd, filter,true, sessionkey);
                if (x.Length==0)
                    Console.WriteLine("Error:: List of Users in SAM Database not retrieved........");
                else
                {
                    base.WriteObject(x);
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nError Occured!!! \n ");
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "VHosts", SupportsShouldProcess = true)]      //Get-VHosts -VirtualPlatform -VirtualizationProductType
    public class getvirtualhosts : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Virtual Platform used.....")]
        [ValidateNotNullOrEmpty]

        public string VirtualPlatform
        {
            set { vpname = value; }
        }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Virtualization Product type...")]
        [ValidateNotNullOrEmpty]

        public string VirtualizationProductType
        {
            set { vproducttype = value; }
        }
        #endregion

        private string vpname;
        private string vproducttype;

        protected override void ProcessRecord()
        {
            #region vars
            var LogResponse = new webproxy.LoginResponse();
            var vhResponse = new webproxy.VHostResponse();
            var vptype = new webproxy.VirtualizationProductType();
            var vplatform = new webproxy.VitualPlatforms();
            string sessionkey;
            #endregion
           
            Fxns f1 = new Fxns();
            try
            {
                if (vpname.ToUpper() == "NONE")
                    vplatform = webproxy.VitualPlatforms.None;
                else
                {
                    vplatform = f1.getplatform(vpname);
                    if (vplatform == webproxy.VitualPlatforms.None)
                        throw new ArgumentException();
                }

                if (vproducttype.ToUpper() == "NONE")
                    vptype = webproxy.VirtualizationProductType.none;
                else
                {
                    vptype = f1.getproducttype(vproducttype);
                    if (vptype == webproxy.VirtualizationProductType.none)
                    {
                        throw new Exception();
                    }
                }
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");

                vhResponse = f1.getVHosts(sessionkey, vplatform, vptype);
                if (vhResponse.StatusCode != 1)
                    Console.WriteLine("Error:: " + vhResponse.StatusCodeMessage);
                else
                {
                    base.WriteObject(vhResponse);
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nWrong VirtualPlatform entered!!!\nPlease check and enter again.......\n");
            }
            catch (Exception)
            {
                Console.WriteLine("\nWrong Virtualization ProductType specified!!!\nPlease check it again!!!\n");
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "DesktopCenters", SupportsShouldProcess = true)] //Get-DesktopCenters -VirtualizationType -VirtualizationProductType
    public class getDC : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the VirtualizationType.....")]
        [ValidateNotNullOrEmpty]

        public string VirtualizationType
        {
            set { vtype = value; }
        }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Virtualization Product type...")]
        [ValidateNotNullOrEmpty]

        public string VirtualizationProductType
        {
            set { vproducttype = value; }
        }
        #endregion

        private string vtype;
        private string vproducttype;
 
        protected override void ProcessRecord()
        {
            var dcResponse = new webproxy.DataCenterResponse();
            var virtype = new webproxy.VirtualizationType();
            var vptype = new webproxy.VirtualizationProductType();
            string sessionkey;            
            try
            {
                Fxns f1 = new Fxns();

                if (vtype.ToUpper() == "NONE")
                    virtype = webproxy.VirtualizationType.none;
                else
                {
                    virtype = f1.getvirtualizationtype(vtype);
                    if (virtype == webproxy.VirtualizationType.none)
                        throw new ArgumentException();
                }

                if (vproducttype.ToUpper() == "NONE")
                    vptype = webproxy.VirtualizationProductType.none;
                else
                {
                    vptype = f1.getproducttype(vproducttype);
                    if (vptype == webproxy.VirtualizationProductType.none)
                    {
                        throw new Exception();
                    }
                }
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                dcResponse = f1.getdatacenters(sessionkey,virtype,vptype);
                    if (dcResponse.StatusCode != 1)
                        Console.WriteLine("Error:: " + dcResponse.StatusCodeMessage);
                    else
                    {
                        base.WriteObject(dcResponse);
                    }
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nWrong Virtualizationtype entered!!!\nPlease check and enter again.......\n");
            }
            catch (Exception)
            {
                Console.WriteLine("\nWrong Virtualization ProductType specified!!!\nPlease check it again!!!\n");
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "ManagedDesktops", SupportsShouldProcess = true)]  //Get-ManagedDesktops
    public class manageddesktop : PSCmdlet
    {
           
        protected override void ProcessRecord()
        {
            #region vars
            string sessionkey;
            var MDResponse = new webproxy.ManagedDesktopResponse();
            #endregion

            try
            {
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                Fxns f1 = new Fxns();
                MDResponse = f1.getmanageddesktop(sessionkey);
                    if (MDResponse.StatusCode != 1)
                        Console.WriteLine("Error:: " + MDResponse.StatusCodeMessage);
                    else
                    {
                        base.WriteObject(MDResponse);
                }
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "AdminSessions", SupportsShouldProcess = true)]  //Get-AdminSessions
    public class adminsess : PSCmdlet
    {
            protected override void ProcessRecord()
        {
            var adminsessionresponse = new webproxy.GetActiveAdminSessionsResponse();
            var webserv1 = new webproxy.ConnectionBrokerService();
            string sessionkey;

            try
            {
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                if (sessionkey == null)
                    Console.WriteLine("Not logged in....");
                adminsessionresponse = webserv1.GetActiveAdminSessions(sessionkey);
                    if (adminsessionresponse.StatusCode != 1)
                        Console.WriteLine("Error:: " + adminsessionresponse.StatusCodeMessage);
                    else
                    {
                        System.Console.WriteLine("\n--------------------ADMIN SESSIONS-----------------------");
                        System.Console.WriteLine("No. of Active admin sessions are :: " + adminsessionresponse.AdminSessionTable.Length);
                        foreach (webproxy.ArrayOfKeyValueOfguidAdminSessionInfoEDjh4431KeyValueOfguidAdminSessionInfoEDjh4431 pair in adminsessionresponse.AdminSessionTable)
                        {
                            Console.WriteLine("Admin Sessionkey ::" + pair.Key);
                            Console.WriteLine("Admin Username::" + pair.Value.AdminDisplayName);
                            Console.WriteLine("Admin User IPAddress::" + pair.Value.AdminIPAddress);
                            Console.WriteLine("Admin LoginTime::" + pair.Value.LoginTime);
                            Console.WriteLine("---------------------------------------------------------\n");                            
                        }
                    }
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "UserSessions", SupportsShouldProcess = true)]  //Get-UserSessions
    public class usersess : PSCmdlet
    {
        protected override void ProcessRecord()
        {
            var usersessionresponse = new webproxy.GetActiveUserSessionsResponse();
            var webserv1 = new webproxy.ConnectionBrokerService();
            string sessionkey;

            try
            {
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                if (sessionkey == null)
                    Console.WriteLine("Not logged in....");
                usersessionresponse = webserv1.GetActiveUserSessions(sessionkey);
                if (usersessionresponse.StatusCode != 1)
                    Console.WriteLine("Error:: " + usersessionresponse.StatusCodeMessage);
                else
                {
                    System.Console.WriteLine("\n--------------------User SESSIONS-----------------------");
                    System.Console.WriteLine("No. of Active user sessions are :: " + usersessionresponse.ClientSessionTable.Length);
                    foreach (webproxy.ArrayOfKeyValueOfguidUserSessionInfoEDjh4431KeyValueOfguidUserSessionInfoEDjh4431 pair in usersessionresponse.ClientSessionTable)
                    {
                        Console.WriteLine("User Sessionkey ::" + pair.Key);
                        Console.WriteLine("User Diaplay name::" + pair.Value.UserDisplayName);
                        Console.WriteLine("User IPAddress::" + pair.Value.UserIPAddress);
                        Console.WriteLine("User LoginTime::" + pair.Value.LoginTime);
                        Console.WriteLine("---------------------------------------------------------\n");
                    }
                }
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "MDPools", SupportsShouldProcess = true)]   //Get-MDPools
    public class manageddesktoppools : PSCmdlet
    {
        protected override void ProcessRecord()
        {
            string sessionkey;
            var webserv1 = new webproxy.ConnectionBrokerService();
            var mdPoolResponse = new webproxy.MDPoolResponse();
            var mdPoolFilter = new webproxy.MDPoolFilter();
            var mdPoolAttributeSelectFlag = new webproxy.MDPoolAttributeSelectFlag();

            sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
            mdPoolFilter.SelectFlag = webproxy.SelectFlag.All;
            mdPoolAttributeSelectFlag.ReturnAllFlag = true;
            mdPoolResponse = webserv1.GetMDPool(mdPoolFilter, mdPoolAttributeSelectFlag, sessionkey);
            if (mdPoolResponse.StatusCode != 1)
                Console.WriteLine("\nError occured..... \nMessage:: " + mdPoolResponse.StatusCodeMessage);
            else
            {
                base.WriteObject(mdPoolResponse);
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "AdminLogs", SupportsShouldProcess = true)]  //Get-AdminLogs [-starttime -endtime]
    public class adminlogs : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
                    Mandatory = false,
                    ValueFromPipelineByPropertyName = true)]
        public string starttime
        {
            set { stime = DateTime.Parse(value); }
        }

        [Parameter(Position = 1,
                    Mandatory = false,
                    ValueFromPipelineByPropertyName = true)]
        public string endtime
        {
            set { etime = DateTime.Parse(value); }
        }
        #endregion

        public System.DateTime stime = DateTime.Parse("1/1/2011 00:00:00 AM");
        public System.DateTime etime = DateTime.Now;
        protected override void ProcessRecord()
        {
            var adminlogresponse = new webproxy.LogResponse();
            var webserv1 = new webproxy.ConnectionBrokerService();
            var filter1 = new webproxy.LogFilter();
            string sessionkey;

            try
            {
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                Fxns f1 = new Fxns();
                filter1.LogOwnerType = webproxy.LogOwnerType.Admin;
                filter1.SelectFlagSpecified = true;
                filter1.SelectFlag = true;
                filter1.LogStartTime = stime;
                filter1.LogEndTimeSpecified = true;
                filter1.LogEndTime = etime;
                filter1.LogStartTimeSpecified = true;

                filter1.LogOwnerTypeSpecified = true;
                adminlogresponse = webserv1.GetLogs(filter1, sessionkey);
                if (adminlogresponse.StatusCode != 1)
                    Console.WriteLine("Error:: " + adminlogresponse.StatusCodeMessage);
                else
                {
                    System.Console.WriteLine("\n--------------------ADMIN LOGS---------------------------");
                    Console.WriteLine("Count:: " + adminlogresponse.ListOfLog.Length);
                    for (int i = 0; i < adminlogresponse.ListOfLog.Length; i++)
                    {
                        Console.WriteLine("Logtime::" + adminlogresponse.ListOfLog[i].LogTime);
                        Console.WriteLine("Logtype::" + adminlogresponse.ListOfLog[i].LogType);
                        Console.WriteLine("Level::" + adminlogresponse.ListOfLog[i].Level);
                        Console.WriteLine("User::" + adminlogresponse.ListOfLog[i].User);
                        Console.WriteLine("IP Address::" + adminlogresponse.ListOfLog[i].UserIPv4Address);
                        Console.WriteLine("Target Name::" + adminlogresponse.ListOfLog[i].TargetName);
                        Console.WriteLine("Target Type::" + adminlogresponse.ListOfLog[i].TargetType);
                        Console.WriteLine("Message::" + adminlogresponse.ListOfLog[i].Message);
                        Console.WriteLine("---------------------------------------------------------\n");
                    }
                }
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }

        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "UserLogs", SupportsShouldProcess = true)]  //Get-UserLogs [-StartTime -EndTime]
    public class userlogs : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
                    Mandatory = false,
                    ValueFromPipelineByPropertyName = true)]
        public string StartTime
        {
            set { stime = DateTime.Parse(value); }
        }

        [Parameter(Position = 1,
                    Mandatory = false,
                    ValueFromPipelineByPropertyName = true)]
        public string EndTime
        {
            set { etime = DateTime.Parse(value); }
        }
        #endregion

        public System.DateTime stime = DateTime.Parse("1/1/2011 00:00:00 AM");
        public System.DateTime etime = DateTime.Now;
        protected override void ProcessRecord()
        {
            var userlogresponse = new webproxy.LogResponse();
            var webserv1 = new webproxy.ConnectionBrokerService();
            var filter1 = new webproxy.LogFilter();
            string sessionkey;

                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                Fxns f1 = new Fxns();
                filter1.LogOwnerType = webproxy.LogOwnerType.User;
                filter1.SelectFlagSpecified = true;
                filter1.SelectFlag = true;
                filter1.LogStartTime = stime;
                filter1.LogEndTimeSpecified = true;
                filter1.LogEndTime = etime;
                filter1.LogStartTimeSpecified = true;
                filter1.LogOwnerTypeSpecified = true;
                userlogresponse = webserv1.GetLogs(filter1, sessionkey);
                if (userlogresponse.StatusCode != 1)
                    Console.WriteLine("Error:: " + userlogresponse.StatusCodeMessage);
                else
                {
                    System.Console.WriteLine("\n--------------------USER LOGS---------------------------");
                    Console.WriteLine("Count:: " + userlogresponse.ListOfLog.Length);
                    for (int i = 0; i < userlogresponse.ListOfLog.Length; i++)
                    {
                        Console.WriteLine("Logtime::" + userlogresponse.ListOfLog[i].LogTime);
                        Console.WriteLine("Logtype::" + userlogresponse.ListOfLog[i].LogType);
                        Console.WriteLine("Level::" + userlogresponse.ListOfLog[i].Level);
                        Console.WriteLine("User::" + userlogresponse.ListOfLog[i].User);
                        Console.WriteLine("IP Address::" + userlogresponse.ListOfLog[i].UserIPv4Address);
                        Console.WriteLine("Target Name::" + userlogresponse.ListOfLog[i].TargetName);
                        Console.WriteLine("Target Type::" + userlogresponse.ListOfLog[i].TargetType);
                        Console.WriteLine("Message::" + userlogresponse.ListOfLog[i].Message);
                        Console.WriteLine("---------------------------------------------------------\n");
                    }
                }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Remove, "DesktopCenter", SupportsShouldProcess = true)]  //Remove-DesktopCenter -Name -VirtualizationType -VirtualizationProductType
    public class removedesktopcenter : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the name of DesktopCenter to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string VirtualizationType
        {
            set { vtype = value; }
        }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Virtualization Type of DesktopCenter to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string VirtualizatioProductType
        {
            set { vprodtype = value; }
        }

        [Parameter(Position = 2,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the virtualization ProductType of DesktopCenter to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string Name
        {
            set { uname = value; }
        }
        #endregion

        private string uname;
        private string vtype;
        private string vprodtype;

        protected override void ProcessRecord()
        {
            #region vars
            var virtype = new webproxy.VirtualizationType();
            var vptype = new webproxy.VirtualizationProductType();
            var webserv1 = new webproxy.ConnectionBrokerService();
            var dcresponse = new webproxy.DataCenterResponse();
            var dcfilter = new webproxy.DataCenterFilter();
            var dcattrselectflag = new webproxy.DCAttributesSelectFlag();
            webproxy.DataCenter[] deldc = new webproxy.DataCenter[1];
            string sessionkey;
            int flag = 0, i = 0;
            #endregion

            Fxns f1 = new Fxns();

            try
            {
                if (vtype.ToUpper() == "NONE")
                    virtype = webproxy.VirtualizationType.none;
                else
                {
                    virtype = f1.getvirtualizationtype(vtype);
                    if (virtype == webproxy.VirtualizationType.none)
                        throw new ArgumentException();
                }

                if (vprodtype.ToUpper() == "NONE")
                    vptype = webproxy.VirtualizationProductType.none;
                else
                {
                    vptype = f1.getproducttype(vprodtype);
                    if (vptype == webproxy.VirtualizationProductType.none)
                    {
                        throw new Exception();
                    }
                }

                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                dcresponse = f1.getdatacenters(sessionkey, virtype, vptype);

                for (i = 0; i < dcresponse.ListOfDC.Length; i++)
                {
                    if (dcresponse.ListOfDC[i].DataCenterName.ToUpper() == uname.ToUpper())
                    {
                        deldc[0] = dcresponse.ListOfDC[i];
                        dcfilter.DataCenterName = dcresponse.ListOfDC[i].DataCenterName;
                        dcfilter.RecordGUID = dcresponse.ListOfDC[i].RecordGUID;
                        Console.WriteLine("DesktopCenter present.... Now deleting it..... ");
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0)
                    Console.WriteLine("DesktopCenter not present!!! Enter Correct user!!!");
                else
                {
                    var deleteresponse = new webproxy.Response();
                    deleteresponse = webserv1.UpdateDataCenter(dcfilter, deldc[0], dcattrselectflag, sessionkey);
                    if (deleteresponse.StatusCode == 1)
                    {
                        base.WriteObject(deleteresponse);
                        Console.WriteLine("\nUser Deleted Successfully..........\n");
                    }
                    else
                        Console.WriteLine("\nError in deleting!!!\nMessage ::" + deleteresponse.StatusCodeMessage);
                }
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nWrong Virtualizationtype entered!!!\nPlease check and enter again.......\n");
            }
            catch (Exception)
            {
                Console.WriteLine("\nWrong Virtualization ProductType specified!!!\nPlease check it again!!!\n");
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Remove, "Client", SupportsShouldProcess = true)]  //Remove-Client -Name [-UserType -Domain]
    public class removeclient : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the name of DesktopCenter to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string Name
        {
            set { uname = value; }
        }

        [Parameter(Position = 0,
        Mandatory = false,
        ValueFromPipelineByPropertyName = true,
        HelpMessage = "Enter the ClientType to be fetched from database...")]
        [ValidateNotNullOrEmpty]

        public string ClientType
        {
            set { ctype = value; }
        }

        [Parameter(Position = 1,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the DomainName to be fetched from database...")]
        [ValidateNotNullOrEmpty]

        public string DomainName
        {
            set { domname = value; }
        }
        #endregion

        private string uname;
        private string ctype = "User";
        private string domname = "localhost";

        protected override void ProcessRecord()
        {
            #region vars
            var ClientResponse = new webproxy.ClientResponse();
            var clientFilter = new webproxy.ClientFilter();
            var clientAttributeSelectFlag = new webproxy.ClientAttributeSelectFlag();
            var webserv1 = new webproxy.ConnectionBrokerService();
            var deleteresponse = new webproxy.Response();
            var filter = new webproxy.ClientType();
            webproxy.Client[] del = new webproxy.Client[1];
            string sessionkey;
            int flag = 0, i = 0;
            #endregion

            try
            {
                Fxns f1 = new Fxns();
                if (ctype.ToUpper() == "NONE")
                    filter = webproxy.ClientType.None;
                else
                {
                    filter = f1.getfilter(ctype);
                    if (filter == webproxy.ClientType.None)
                        throw new ArgumentException();
                }

                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                ClientResponse = f1.getClients(sessionkey, filter, domname);

                for (i = 0; i < ClientResponse.ListOfClients.Length; i++)
                {
                    if (ClientResponse.ListOfClients[i].ClientName.ToUpper() == uname.ToUpper())
                    {
                        clientFilter.CommandTypeFlagSpecified = true;
                        clientFilter.ClientTypeSpecified = true;
                        clientFilter.SelectFlag = webproxy.SelectFlag.UseFilter;
                        clientFilter.SelectFlagSpecified = true;
                        clientFilter.CommandTypeFlag = webproxy.CommandType.Delete;
                        clientFilter.ClientName = ClientResponse.ListOfClients[i].ClientName;
                        clientFilter.RecordGUID = ClientResponse.ListOfClients[i].RecordGUID;
                        clientAttributeSelectFlag.UpdateIsEnabled = true;
                        del[0] = new webproxy.Client();
                        del[0] = ClientResponse.ListOfClients[i];
                        Console.WriteLine("Client present.... Now deleting it..... ");
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0)
                    Console.WriteLine("Client not present!!!Enter Correct Clientname or check the ClientType or DomainName!!!");
                else
                {
                    deleteresponse = webserv1.UpdateClients(clientFilter, del, clientAttributeSelectFlag, sessionkey);
                }
                if (deleteresponse.StatusCode == 1)
                {
                    base.WriteObject(deleteresponse);
                    Console.WriteLine("\nClient Deleted Successfully..........\n");
                }
                else
                    Console.WriteLine("\nError in deleting!!!\nMessage ::" + deleteresponse.StatusCodeMessage);
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nWrong ClientType specified!!!\nPlease check it and try again!!!\n");
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Remove, "VHost", SupportsShouldProcess = true)]  //Remove-VHost -Name [-VirtualPlatform -VirtualizationProductType]
    public class removevhosts : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the name of VHost to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string Name
        {
            set { vname = value; }
        }

        [Parameter(Position = 1,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the VirtualPlatform of VHost to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string VirtualPlatform
        {
            set { vpname = value; }
        }

        [Parameter(Position = 2,
            Mandatory = false,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the VirtualizationProductType of VHost to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string VirtualizationProductType
        {
            set { vproducttype = value; }
        }
        #endregion

        private string vname;
        private string vpname;
        private string vproducttype;

        protected override void ProcessRecord()
        {
            #region vars
            var webserv1 = new webproxy.ConnectionBrokerService();
            var vfilter = new webproxy.VHostFilter();
            var vattributeselectflag = new webproxy.VHAttributeSelectFlag();
            var vhostresponse=new webproxy.VHostResponse();
            webproxy.VirtualizationHost[] delvhost = new webproxy.VirtualizationHost[1];
            var delresponse = new webproxy.Response();
            var vptype = new webproxy.VirtualizationProductType();
            var vplatform = new webproxy.VitualPlatforms();
            string sessionkey;
            int flag = 0, i = 0;
            #endregion

            try
            {
                Fxns f1 = new Fxns();

                if (vpname.ToUpper() == "NONE")
                    vplatform = webproxy.VitualPlatforms.None;
                else
                {
                    vplatform = f1.getplatform(vpname);
                    if (vplatform == webproxy.VitualPlatforms.None)
                        throw new ArgumentException();
                }

                if (vproducttype.ToUpper() == "NONE")
                    vptype = webproxy.VirtualizationProductType.none;
                else
                {
                    vptype = f1.getproducttype(vproducttype);
                    if (vptype == webproxy.VirtualizationProductType.none)
                    {
                        throw new Exception();
                    }
                }

                vfilter.VirtualizationProductType = vptype;
                vfilter.VirtualizationProductTypeSpecified=true;
                vfilter.CommandTypeFlag = webproxy.CommandType.Delete;
                vfilter.CommandTypeFlagSpecified=true;
                vfilter.IsEnabled = 1;
                vfilter.IsEnabledSpecified=true;
                vfilter.VirtualHostType = vplatform;
                vfilter.VirtualHostTypeSpecified=true;
                vfilter.SelectFlag = webproxy.SelectFlag.All;
                vfilter.SelectFlagSpecified=true;


                vattributeselectflag.UpdateIsEnabled=true;
                vattributeselectflag.UpdateIsEnabledSpecified=true;
                vattributeselectflag.ReturnAllFlag = true;
                vattributeselectflag.ReturnAllFlagSpecified=true;
                vattributeselectflag.IsVirtualHostNameRequired = true;
                vattributeselectflag.IsVirtualHostNameRequiredSpecified=true;
                vattributeselectflag.IsVirtualHostTypeRequired = true;
                vattributeselectflag.IsVirtualHostTypeRequiredSpecified=true;


                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                vhostresponse = f1.getVHosts(sessionkey, vplatform, vptype);
                for ( i = 0; i < vhostresponse.ListOfVH.Length; i++)
                {
                    if (vhostresponse.ListOfVH[i].VirtualHostName.ToUpper() == vname.ToUpper())
                    {
                        delvhost[0] = new webproxy.VirtualizationHost();
                        vfilter.RecordGUID = vhostresponse.ListOfVH[i].RecordGUID;
                        vfilter.VirtualHostName = vhostresponse.ListOfVH[i].VirtualHostName;
                        delvhost[0] = vhostresponse.ListOfVH[i];
                        Console.WriteLine("VHost present.... Now deleting it..... ");
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0)
                    Console.WriteLine("VHost not present!!! Enter Correct VHost!!!");
                else
                {
                    delresponse = webserv1.UpdateVHost(vfilter, delvhost[0], vattributeselectflag, sessionkey);
                    // delresponse.StatusCode = 2;
                }
                    if (delresponse.StatusCode == 1)
                        Console.WriteLine("\nVHost Deleted Successfully..........\n");
                    else
                        Console.WriteLine("\nError in deleting!!!\nMessage ::" + delresponse.StatusCodeMessage);
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nWrong VirtualPlatform entered!!!\nPlease check and enter again.......\n");
            }
            catch (Exception)
            {
                Console.WriteLine("\nWrong Virtualization ProductType specified!!!\nPlease check it again!!!\n");
            }
        }
    }
   
//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Remove, "MDPool", SupportsShouldProcess = true)]   //Remove-MDPool -Name -DesktopCenter(Here it is Object of DC)
    public class removemdpool : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the name of MDPool to be deleted......")]
        [ValidateNotNullOrEmpty]

        public string Name
        {
            set { poolname = value; }
        }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the DesktopCenter Rresponse object of which MDPool is the part......")]
        [ValidateNotNullOrEmpty]

        public webproxy.DataCenter DCName
        {
            set { dcentername = value; }
        }
        #endregion

        private string poolname;
        private webproxy.DataCenter dcentername;

        protected override void ProcessRecord()
        {
            string sessionkey;
            var webserv1 = new webproxy.ConnectionBrokerService();
            var mdpool = new webproxy.MDPool();
            var mdPoolResponse = new webproxy.MDPoolResponse();
            var mdPoolFilter = new webproxy.MDPoolFilter();
            var mdPoolAttributeSelectFlag = new webproxy.MDPoolAttributeSelectFlag();

            sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
            mdPoolFilter.SelectFlag = webproxy.SelectFlag.All;
            mdPoolFilter.DatacenterGUID = dcentername.RecordGUID;
            mdPoolFilter.MDPoolName = poolname;
            mdPoolFilter.CommandTypeFlag = webproxy.CommandType.Delete;
            mdPoolFilter.CommandTypeFlagSpecified = true;

            mdpool.DatacenterGUID = dcentername.RecordGUID;
            mdpool.MDPoolName = poolname;

            mdPoolAttributeSelectFlag.ReturnAllFlag = true;
            mdPoolAttributeSelectFlag.ReturnAllFlagSpecified = true;
            mdPoolAttributeSelectFlag.IsDatacenterGUIDRequired = true;
            mdPoolAttributeSelectFlag.IsDatacenterGUIDRequiredSpecified = true;

            mdPoolResponse = webserv1.UpdateMDPool(mdPoolFilter, mdpool, mdPoolAttributeSelectFlag, sessionkey);

            if (mdPoolResponse.StatusCode != 1)
                Console.WriteLine("\nError occured..... \nMessage:: " + mdPoolResponse.StatusCodeMessage);
            else
            {
                Console.WriteLine("---------------------------------------------------------");
                Console.WriteLine("MDPool deleted successfully.........");
                Console.WriteLine("---------------------------------------------------------\n");
            }
        }
    }
 
    //==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Reset, "ManagedDesktop", SupportsShouldProcess = true)]  //Reset-managedDesktop -MDPoolName -MDName -Operation
    public class updatemanageddesktop : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the name of MDPool to be modified......")]
        [ValidateNotNullOrEmpty]

        public string MDPoolName
        {
            set { mpoolname = value; }
        }

        [Parameter(Position = 1,
           Mandatory = true,
           ValueFromPipelineByPropertyName = true,
           HelpMessage = "Enter the name of ManagedDesktop......")]
        [ValidateNotNullOrEmpty]



        public string MDName
        {
            set { mname = value; }
        }

        [Parameter(Position = 2,
         Mandatory = true,
         ValueFromPipelineByPropertyName = true,
         HelpMessage = "Enter the operation number from 1.start 2.stop 3.restart 4.suspend 5.resume 6.disconnect......")]
        [ValidateNotNullOrEmpty]



        public string Operation
        {
            set { ch = value; }
        }
        #endregion

        private string mpoolname;
        private string mname;
        private string ch;


        protected override void ProcessRecord()
        {
            #region vars
            var webserv1 = new webproxy.ConnectionBrokerService();
            var mfilter = new webproxy.ManagedDesktopFilter();
            var mresponse = new webproxy.ManagedDesktopResponse();
            var mselectflag = new webproxy.MDAttributeSelectFlag();
            webproxy.ManagedDesktop[] mdesktop = new webproxy.ManagedDesktop[1];
            var moperation = new webproxy.MDOperationType();
            string sessionkey;
            int flags = 0, i = 0;
            #endregion

            mfilter.VirtualHostType = webproxy.VitualPlatforms.ParallelsVirtuozzo;
            mfilter.VirtualHostTypeSpecified = true;
            mfilter.ReturnAll = true;
            mfilter.ReturnAllSpecified = true;
            mfilter.GetMDByMDPool = true;
            mfilter.GetMDByMDPoolSpecified = true;
            mfilter.SelectFlag = webproxy.SelectFlag.All;
            mfilter.SelectFlagSpecified = true;

            mselectflag.IsMDNameRequired = false;
            mselectflag.ReturnAllFlag = true;
            mselectflag.ReturnAllFlagSpecified = true;

            mdesktop[0] = new webproxy.ManagedDesktop();


            try
            {
                Fxns f1 = new Fxns();
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                mresponse = webserv1.GetManagedDesktop(mfilter, mselectflag, sessionkey);

                for (i = 0; i < mresponse.ListOfMD.Length; i++)
                {
                    if (mresponse.ListOfMD[i].MDPoolName.ToUpper() == mpoolname.ToUpper() && mresponse.ListOfMD[i].MDName.ToUpper() == mname.ToUpper())
                    {
                        mfilter.RecordGUID = mresponse.ListOfMD[i].RecordGUID;
                        mfilter.MDName = mresponse.ListOfMD[i].MDName;
                        mdesktop[0] = mresponse.ListOfMD[i];
                        flags = 1;
                        break;
                    }
                }
                if (flags == 0)
                    Console.WriteLine("Machine not present!!! Enter Correct machine!!!");
                else
                {

                    switch (ch)
                    {
                        case "start": moperation = webproxy.MDOperationType.Start;
                            break;

                        case "stop": moperation = webproxy.MDOperationType.Stop;
                            break;

                        case "restart": moperation = webproxy.MDOperationType.Restart;
                            break;

                        case "delete": moperation = webproxy.MDOperationType.Delete;
                            break;

                        case "suspend": moperation = webproxy.MDOperationType.Suspend;
                            break;

                        case "resume": moperation = webproxy.MDOperationType.Resume;
                            break;

                        case "disconnect": moperation = webproxy.MDOperationType.Disconnect;
                            break;
                    }

                    var moperator = webserv1.MDOperator(mdesktop, moperation, true, null, sessionkey);

                    if (moperator.StatusCode == 1)
                        Console.WriteLine("\nmachine state changed Successfully..........\n");
                    else
                        Console.WriteLine("\nError in changing!!!\nMessage ::" + moperator.StatusCodeMessage);


                }

            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }

        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "AdminLogout", SupportsShouldProcess = true)]  //Get-AdminLogout
    public class admlogout : PSCmdlet
    {
        protected override void ProcessRecord()
        {
            string sessionkey;
            sessionkey=System.Environment.GetEnvironmentVariable("sessionkey");
            Fxns f1 = new Fxns();
            f1.logout(sessionkey);
            Console.WriteLine("\nLogged out successfully.....\n");
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Add, "VHost", SupportsShouldProcess = true)]  //Add-VHost -Name -VirtualizationType -VirtualizationproductType -ServerIP -Username -Password
    public class addvhost : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the name of VHost to be added......")]
        [ValidateNotNullOrEmpty]

        public string Name
        {
            set { vname = value; }
        }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the VirtualizationType of VHost to be added......")]
        [ValidateNotNullOrEmpty]

        public string VirtualizationType
        {
            set { vpname = value; }
        }

        [Parameter(Position = 2,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the VirtualizationProductType of VHost to be added......")]
        [ValidateNotNullOrEmpty]

        public string VirtualizationProductType
        {
            set { vproducttype = value; }
        }

        [Parameter(Position = 3,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Server IP......")]
        [ValidateNotNullOrEmpty]

        public string ServerIP
        {
            set { ip = value; }
        }

        [Parameter(Position = 4,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the Username......")]
        [ValidateNotNullOrEmpty]

        public string UserName
        {
            set { username = value; }
        }

        [Parameter(Position = 5,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the password......")]
        [ValidateNotNullOrEmpty]

        public string Password
        {
            set { passwd = value; }
        }

        #endregion

        private string vname;
        private string vpname;
        private string vproducttype;
        private string ip;
        private string username;
        private string passwd;

        protected override void ProcessRecord()
        {
            #region vars
            var webserv1 = new webproxy.ConnectionBrokerService();
            var vfilter = new webproxy.VHostFilter();
            var vattributeselectflag = new webproxy.VHAttributeSelectFlag();
            var vhostresponse = new webproxy.VHostResponse();
            webproxy.VirtualizationHost virtualizationhost = new webproxy.VirtualizationHost();
            var vptype = new webproxy.VirtualizationProductType();
            var virttype = new webproxy.VirtualizationType();
            string sessionkey;
            #endregion

            try
            {
                Fxns f1 = new Fxns();
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                if (vpname.ToUpper() == "NONE")
                    virttype = webproxy.VirtualizationType.none;
                else
                {
                    virttype = f1.getvirtualizationtype(vpname);
                    if (virttype == webproxy.VirtualizationType.none)
                        throw new ArgumentException();
                }

                if (vproducttype.ToUpper() == "NONE")
                    vptype = webproxy.VirtualizationProductType.none;
                else
                {
                    vptype = f1.getproducttype(vproducttype);
                    if (vptype == webproxy.VirtualizationProductType.none)
                    {
                        throw new Exception();
                    }
                }

                vfilter.CommandTypeFlag = webproxy.CommandType.Insert;
                vfilter.CommandTypeFlagSpecified = true;
                vfilter.IsEnabled = 1;
                vfilter.IsEnabledSpecified = true;
                
                virtualizationhost.HostAddress = ip;
                virtualizationhost.VirtualHostName = vname;
                virtualizationhost.UserName = username;
                virtualizationhost.Password = passwd;
                virtualizationhost.Port = 4433;
                virtualizationhost.PortSpecified = true;
                virtualizationhost.VirtualHostType = virttype;
                virtualizationhost.VirtualHostTypeSpecified = true;
                virtualizationhost.VirtualizationProductType = vptype;
                virtualizationhost.VirtualizationProductTypeSpecified = true;
                virtualizationhost.IsEnabled = 1;
                virtualizationhost.IsEnabledSpecified = true;
                virtualizationhost.IsAssigned = 0;
                virtualizationhost.IsAssignedSpecified = true;

                var vhattributeselectflag = new webproxy.VHAttributeSelectFlag();
                vhattributeselectflag.IsHostAddressRequired = true;
                vhattributeselectflag.IsHostAddressRequiredSpecified = true;
                vhattributeselectflag.IsPasswordRequired = true;
                vhattributeselectflag.IsPasswordRequiredSpecified = true;
                vhattributeselectflag.IsPortRequired = true;
                vhattributeselectflag.IsPortRequiredSpecified = true;
                vhattributeselectflag.IsEnabledRequired = true;
                vhattributeselectflag.IsEnabledRequiredSpecified = true;
                vhattributeselectflag.IsUserNameRequired = true;
                vhattributeselectflag.IsUserNameRequiredSpecified = true;
                vhattributeselectflag.UpdateIsEnabled = true;
                vhattributeselectflag.UpdateIsEnabledSpecified = true;
                vhattributeselectflag.IsAssignedRequired = false;
                vhattributeselectflag.IsAssignedRequiredSpecified = true;
                vhattributeselectflag.IsVirtualHostNameRequired = true;
                vhattributeselectflag.IsVirtualHostNameRequiredSpecified = true;
                vhattributeselectflag.IsVirtualHostTypeRequired = true;
                vhattributeselectflag.IsVirtualHostTypeRequiredSpecified = true;
                vhattributeselectflag.IsVirtualizationProductTypeRequired = true;
                vhattributeselectflag.IsVirtualizationProductTypeRequiredSpecified = true;
                vhattributeselectflag.ReturnAllFlag = true;
                vhattributeselectflag.ReturnAllFlagSpecified = true;
                vhattributeselectflag.IsGUIDRequired = false;
                vhattributeselectflag.IsGUIDRequiredSpecified = true;

                vhostresponse = webserv1.UpdateVHost(vfilter, virtualizationhost, vhattributeselectflag, sessionkey);

                if (vhostresponse.StatusCode == 1)
                {
                    Console.WriteLine("\nVHost added successfully.......\n");
                }
                else
                {
                    Console.WriteLine("\nError occured!!! " + vhostresponse.StatusCode);
                }
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nWrong VirtualPlatform entered!!!\nPlease check and enter again.......\n");
            }
            catch (Exception)
            {
                Console.WriteLine("\nWrong values specified!!!\nPlease check it again!!!\n");
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "VirtualizationTypes", SupportsShouldProcess = true)]  //Get-VirtualizationType
    public class virtualizationtypes : PSCmdlet
    {
        protected override void ProcessRecord()
        {
            try
            {
                string[] vnames = Enum.GetNames(typeof(webproxy.VirtualizationType));
                WriteObject(vnames);
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "VirtualizationProductTypes", SupportsShouldProcess = true)]  //Get-VirtualizationProductType
    public class virtualizationproducttypes : PSCmdlet
    {
        protected override void ProcessRecord()
        {
            try
            {
                string[] vpnames = Enum.GetNames(typeof(webproxy.VirtualizationProductType));
                WriteObject(vpnames);
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
        }
    }

//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "VirtualPlatforms", SupportsShouldProcess = true)]  //Get-VirtualizationPlatforms
    public class virtualplatforms : PSCmdlet
    {
        protected override void ProcessRecord()
        {
            try
            {
                string[] vplatformnames = Enum.GetNames(typeof(webproxy.VitualPlatforms));
                WriteObject(vplatformnames);
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
        }
    }

//==============================================================================================================================================//
    /*
    [Cmdlet("Update", "VHostDataCenter", SupportsShouldProcess = true)]  //Remove-VHost -Name [-VirtualPlatform -VirtualizationProductType]
    public class updatevhosts : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the VHost to be updated......")]
        [ValidateNotNullOrEmpty]

        public webproxy.VirtualizationHost VHost
        {
            set { vhost = value; }
        }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the DataCenter to be assigned......")]
        [ValidateNotNullOrEmpty]

        public webproxy.DataCenter DataCenter
        {
            set { dcenter = value; }
        }
        #endregion

        private webproxy.VirtualizationHost vhost;
        private webproxy.DataCenter dcenter;

        protected override void ProcessRecord()
        {
            #region vars
            var webserv1 = new webproxy.ConnectionBrokerService();
            var vfilter = new webproxy.VHostFilter();
            var vattributeselectflag = new webproxy.VHAttributeSelectFlag();
            var updateresponse = new webproxy.Response();
            string sessionkey;
            #endregion

            try
            {
                Fxns f1 = new Fxns();
                
                vfilter.VirtualizationProductType = vhost.VirtualizationProductType;
                vfilter.VirtualizationProductTypeSpecified = true;
                vfilter.CommandTypeFlag = webproxy.CommandType.Update;
                vfilter.CommandTypeFlagSpecified = true;
                vfilter.IsEnabled = 1;
                vfilter.IsEnabledSpecified = true;
                vfilter.SelectFlag = webproxy.SelectFlag.All;
                vfilter.SelectFlagSpecified = true;
                vfilter.VirtualHostName = vhost.VirtualHostName;
                //vfilter.MasterGUID = "0";

                vhost.MasterGUID = dcenter.RecordGUID;
                vhost.pimMembership = webproxy.PIMMembership.Salve;
                vhost.pimMembershipSpecified = true;
                vhost.VirtualHostName = "dd";
                
                vattributeselectflag.UpdateIsEnabled = true;
                vattributeselectflag.UpdateIsEnabledSpecified = true;
                vattributeselectflag.IsVirtualHostTypeRequired = true;
                vattributeselectflag.IsVirtualHostTypeRequiredSpecified = true;
                vattributeselectflag.IsEnabledRequired = true;
                vattributeselectflag.IsEnabledRequiredSpecified = true;
                vattributeselectflag.UpdateIsEnabled = true;
                vattributeselectflag.UpdateIsEnabledSpecified = true;
                vattributeselectflag.UpdateMasterGUID = true;
                vattributeselectflag.UpdateMasterGUIDSpecified = true;
                vattributeselectflag.IsVirtualHostNameRequired = true;    // If I don't specify this here, then name is not changed...
                vattributeselectflag.IsVirtualHostNameRequiredSpecified = true;
                vattributeselectflag.UpdateIsAssigned = true;
                vattributeselectflag.UpdateIsAssignedSpecified = true;
                vattributeselectflag.UpdatePIMMembership = true;
                vattributeselectflag.UpdatePIMMembershipSpecified = true;

                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                
                updateresponse = webserv1.UpdateVHost(vfilter, vhost, vattributeselectflag, sessionkey);

                if (updateresponse.StatusCode == 1)
                    Console.WriteLine("\nVHost updated Successfully..........\n");
                else
                    Console.WriteLine("\nError in updating!!!\nMessage ::" + updateresponse.StatusCodeMessage);
            }
            catch (Exception)
            {
                Console.WriteLine("\nError occured..........\n");
            }
        }
    }
    */
//==============================================================================================================================================//

    [Cmdlet(VerbsCommon.Get, "DCHost", SupportsShouldProcess = true)]     //Get-DCHost
    public class getdchost : PSCmdlet
    {
        
        protected override void ProcessRecord()
        {
            #region vars
            string sessionkey;
            var s1=new webproxy.ConnectionBrokerService();
            var dchostresponse = new webproxy.DCHostResponse();
            var dchostfilter = new webproxy.DCHostFilter();
            var dchostattributeselectflag = new webproxy.DCHostAttributesSelectFlag();
            #endregion

            try
            {
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                dchostfilter.SelectFlag = webproxy.SelectFlag.All;
                dchostfilter.SelectFlagSpecified = true;

                dchostattributeselectflag.ReturnAllFlag = 1;
                dchostattributeselectflag.ReturnAllFlagSpecified = true;

                dchostresponse = s1.GetDCHost(dchostfilter, dchostattributeselectflag, sessionkey);
                if (dchostresponse.StatusCode == 1)
                    WriteObject(dchostresponse);
                else
                    Console.WriteLine(dchostresponse.StatusCodeMessage);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nError occured!!!\n");
            }
        }
    }

//==============================================================================================================================================//

    //*********(Commands to be run in powershell)*************

    //$x=Get-VHosts parallelsvirtuozzo parallelscontainer 
    //$y=Get-DesktopCenters parallels parallelscontainer
    //Assign-VHosttoDC $x.ListOfVH[0] $y.ListOfDC[0]

    [Cmdlet("Assign","VHosttoDC", SupportsShouldProcess = true)]     //Add-VHosttoDC -VHost -DesktopCenter
    public class assignvhosttodc : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the DCHost......")]
        [ValidateNotNullOrEmpty]

        public webproxy.VirtualizationHost VHost
        {
            set { vhost = value; }
        }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the DataCenter to be assigned......")]
        [ValidateNotNullOrEmpty]

        public webproxy.DataCenter DataCenter
        {
            set { dcenter = value; }
        }
        #endregion

        private webproxy.VirtualizationHost vhost;
        private webproxy.DataCenter dcenter;
        protected override void ProcessRecord()
        {
            #region vars
            string sessionkey;
            var s1 = new webproxy.ConnectionBrokerService();
            var dchostresponse = new webproxy.DCHostResponse();
            webproxy.DataCenterHost[] dchost = new webproxy.DataCenterHost[1];
            #endregion

            try
            {
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                
                dchost[0] = new webproxy.DataCenterHost();
                dchost[0].VirtualHostGUID = vhost.RecordGUID;
                dchost[0].DataCenterGUID = dcenter.RecordGUID;
                dchostresponse = s1.AssignVHostToDC(dcenter.RecordGUID, dchost, sessionkey);
                if (dchostresponse.StatusCode == 1)
                {
                    WriteObject(dchostresponse);  
                }
                else
                    Console.WriteLine(dchostresponse.StatusCodeMessage);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nError occured!!!\n");
            }
        }
    }

//==============================================================================================================================================//
    /*
    [Cmdlet(VerbsCommon.Add, "DesktopCenter", SupportsShouldProcess = true)]  //Add-DesktopCenter -Name -VirtualizationType
    public class adddesktopcenter : PSCmdlet
    {
        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the name of DataCenter to be added......")]
        [ValidateNotNullOrEmpty]

        public string Name
        {
            set { vname = value; }
        }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Enter the VirtualizationType of Datacenter to be added......")]
        [ValidateNotNullOrEmpty]

        public string VirtualizationType
        {
            set { vpname = value; }
        }

        #endregion

        private string vname;
        private string vpname;
        
        protected override void ProcessRecord()
        {
            #region vars
            var webserv1 = new webproxy.ConnectionBrokerService();
            var dcenterfilter = new webproxy.DataCenterFilter();
            var dcattributeselectflag = new webproxy.DCAttributesSelectFlag();
            var dcresponse = new webproxy.DataCenterResponse();
            var datacenter = new webproxy.DataCenter();
            var virttype = new webproxy.VirtualizationType();
            string sessionkey;
            #endregion

            try
            {
                Fxns f1 = new Fxns();
                sessionkey = System.Environment.GetEnvironmentVariable("sessionkey");
                if (vpname.ToUpper() == "NONE")
                    virttype = webproxy.VirtualizationType.none;
                else
                {
                    virttype = f1.getvirtualizationtype(vpname);
                    if (virttype == webproxy.VirtualizationType.none)
                        throw new ArgumentException();
                }

                dcenterfilter.CommandTypeFlag = webproxy.CommandType.Insert;
                dcenterfilter.CommandTypeFlagSpecified = true;
                dcenterfilter.VirtualizationProductTypeSpecified = false;
                dcenterfilter.SelectFlag = webproxy.SelectFlag.UseFilter;
                dcenterfilter.SelectFlagSpecified = true;

                datacenter.DataCenterName = vname;
                datacenter.DatacenterType = virttype;
                datacenter.DatacenterTypeSpecified = true;

                dcattributeselectflag.IsDatacenterTypeRequired = 1;
                dcattributeselectflag.IsDatacenterTypeRequiredSpecified = true;
                dcattributeselectflag.IsDCNameRequired = 1;
                dcattributeselectflag.IsDCNameRequiredSpecified = true;
                dcattributeselectflag.ReturnAllFlag = 1;
                dcattributeselectflag.ReturnAllFlagSpecified = true;

                dcresponse = webserv1.UpdateDataCenter(dcenterfilter, datacenter, dcattributeselectflag, sessionkey);

                if (dcresponse.StatusCode == 1)
                {
                    Console.WriteLine("\nDataCenter added successfully.......\n");
                }
                else
                {
                    Console.WriteLine("\nError occured!!! " + dcresponse.StatusCode);
                }
            }
            catch (UnauthorizedAccessException x)
            {
                Console.WriteLine("EXCEPTION CAUGHT:: {0}", x);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("\nWrong VirtualType entered!!!\nPlease check and enter again.......\n");
            }
            catch (Exception)
            {
                Console.WriteLine("\nWrong values specified!!!\nPlease check it again!!!\n");
            }
        }
    }
    */
    //==============================================================================================================================================//

}